package b3.widget.home
{
	import b3.net.*;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;

	public class SwitchSceneScreen extends BasicWidget
	{
		private	var timer:Timer;
		private var layerHeight:int;
			
		public function SwitchSceneScreen()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			this.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			timer = new Timer(200);
			timer.addEventListener(TimerEvent.TIMER, onTimerTick);
			timer.start();
			var gfx:Graphics = this.graphics;
			gfx.clear();
			gfx.moveTo(0, 0);
			gfx.beginFill(0x00AAAA, 0.2);
			gfx.lineTo(BFont.stageWidth, 0);
			gfx.lineTo(BFont.stageWidth, BFont.stageHeight);
			gfx.lineTo(0, BFont.stageHeight);
			gfx.lineTo(0, 0);
			gfx.endFill();
			layerHeight = 0;
		}

		private function onRemovedFromStage(event:Event):void
		{
			timer.stop();
			timer = null;
		}
		
		private function onTimerTick(event:Event):void
		{
			var Brick:Class = ResourceHelper.getInstance().getClassByName("SwitchBrick");
			for (var i:int = 0; i < BFont.stageWidth / 50 + 1; i++)
			{
				var brick:Sprite = new Brick();
				brick.x = i * 50 - 25 * (layerHeight % 2);
				brick.y = BFont.stageHeight - 50 - 50 * layerHeight;
				addChild(brick);
			} 
			if (layerHeight < BFont.stageHeight / 50)
				layerHeight++;
			else
				close();
		}
	
		
	}
}